package com.pa165.languageschoolpersistence.DAO;

import com.pa165.languageschoolpersistence.Exceptions.IllegalArgumentPersistenceException;
import com.pa165.languageschoolpersistence.Exceptions.ServiceFailureException;
import com.pa165.languageschoolpersistence.entities.Lecture;
import com.pa165.languageschoolpersistence.entities.Student;
import java.util.List;

/**
 *
 * @author Jiri Uhlir
 *
 * This Interface represents DAO for handling Students. It contains basic CRUD
 * operations. One student can be enrolled in many students. More students can
 * be enrolled in one student.
 */
public interface StudentDAO {

    /**
     * Method for adding Students. For conventions of a valid student see
     * Student entity. If a student is not in the database, it returns the
     * student added. If a student is already in the database, it returns a null
     * value.
     *
     * @param student student to be added.
     * @return Null if already in database, Student added instead
     * @throws IllegalArgumentPersistenceException if student is invalid
     * @throws ServiceFailureException if a problem during adding occurs.
     */
    public Student add(Student student) throws ServiceFailureException;

    /**
     * Method for removing Students. For conventions of a valid student see
     * Student entity.
     *
     * @param student student to be removed.
     * @throws IllegalArgumentPersistenceException if student is invalid
     * @throws ServiceFailureException is a problem during removal occurs
     */
    public void remove(Student student) throws ServiceFailureException;

    /**
     * Method for modifying Students. For conventions of a valid student see
     * Student entity.
     *
     * @param student student to be modified.
     * @return Modified Student or null if student is not in the database.
     * @throws IllegalArgumentPersistenceException if student is invalid
     * @throws ServiceFailureException if a problem during adding occures
     */
    public Student modify(Student student) throws ServiceFailureException;

    /**
     * Method for retrieving Students. For conventions of a valid student see
     * Student entity. Method gets student by input ID.
     *
     * @param id ID to be searched for.
     * @return Null if not in database, Student found instead
     * @throws IllegalArgumentPersistenceException if id is invalid(for details
     * see Student entity)
     * @throws ServiceFailureException if a problem during search occures.
     */
    public Student get(Long id) throws IllegalArgumentPersistenceException;

    /**
     * Method for retrieving all Students. For conventions of a valid student
     * see Student entity. Method gets all students.
     *
     * @return Empty list if no student , list of students found instead
     * @throws ServiceFailureException if a problem during search occures.
     */
    public List<Student> getAll() throws IllegalArgumentPersistenceException;

    /**
     * Method for enrolling Student to Lecture. For conventions of a valid
     * Lecture see Lecture entity. Method that will add lecture to the list of
     * lectures of the student. Calling enroll to enrolled lecture has no
     * effect, returns null. Lecture can be enrolled to any number of students.
     *
     * @param student Student to be enrolled.
     * @param lecture Lecture to which the student enrolls.
     * @return lecture to which was student enrolled, null if he was already
     * enrolled
     * @throws IllegalArgumentPersistenceException if lecture is invalid(for
     * details see Lecture entity)
     * @throws ServiceFailureException if a problem during process occures.
     */
    public Lecture enrollStudentToLecture(Lecture lecture, Student student) throws IllegalArgumentPersistenceException;

    /**
     * Method for retrieving Students by lecture. For conventions of a valid
     * lecture see Lecture entity. Method gets student by input Lecture.
     *
     * @param lecture lecture to be searched for.
     * @return Null if no such student in database, list of students found
     * instead
     * @throws IllegalArgumentPersistenceException if lecture is invalid(for
     * details see Lecture entity)
     * @throws ServiceFailureException if a problem during search occurs.
     */
    public List<Student> findByLecture(Lecture lecture) throws IllegalArgumentPersistenceException;

    /**
     * Method for retrieving Students by name. For conventions of a valid
     * student see Student entity. Method gets student by input name.
     *
     * @param name name to be searched for.
     * @return Null if no such student in database, list of students found
     * instead
     * @throws IllegalArgumentPersistenceException if name is invalid(for
     * details see Student entity)
     * @throws ServiceFailureException if a problem during search occures.
     */
    public List<Student> findByName(String name) throws IllegalArgumentPersistenceException;
    
    public Student getByLogin(String login) throws IllegalArgumentPersistenceException;
}
